package com.example.demo_one.kotlin

fun main() {
    val car = Car("五菱宏光")
    car.show()
    val car1 = Car("大卡车", 8)
    car1.show()
}

class Car(var name:String){
    var wheels = 0
    constructor(name:String, wheels: Int): this(name){
        this.wheels = wheels
    }
    // 初始代码块
    init {
        when(name){
            "五菱宏光" -> wheels = 4
            "大卡车" -> wheels = 8
            "保时捷" -> wheels = 4
            "小汽车" -> wheels = 4
            "自行车" ->wheels = 2
            else -> wheels = 4
        }
    }
    fun show(){
        println("$name wheels: $wheels")
    }

}